package com.lzw.controller.superAdmin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzw.anno.Log;
import com.lzw.pojo.Bills;
import com.lzw.pojo.StockEntries;
import com.lzw.service.superAdmin.BillsManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/BillsManage")
public class BillsManage {

    @Autowired
    private BillsManageService billsManageService;

    @GetMapping("/list")
    public PageInfo<Bills> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate billDate,
            String medicine){
        PageHelper.startPage(pageNum,pageSize);
        List<Bills> list = billsManageService.list(pageNum, pageSize, medicine, billDate);
        return new PageInfo<>(list);
    }

    //批量删除
    @Log
    @DeleteMapping("/delete/{ids}")
    public String delete(@PathVariable List<Integer> ids){
        billsManageService.delete(ids);
        return "删除成功";
    }

    //添加
    @Log
    @PostMapping("/add")
    public String add(@RequestBody Bills bills) {
        billsManageService.add(bills);
        return "添加成功";
    }

    //更新
    @Log
    @PutMapping("/update")
    public String update(@RequestBody Bills bills){
        billsManageService.update(bills);
        return "更新成功";
    }
}
